package com.wxyzz.satserver.user.controller;


import com.wxyzz.common.core.annotation.NoLoginCheck;
import com.wxyzz.common.core.common.R;

import com.wxyzz.common.core.entity.User;

import com.wxyzz.satserver.user.param.UserParam;
import com.wxyzz.satserver.user.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * --- 加油，努力 ---
 *
 * @Author XYP
 * @Date 2024/11/3
 * @Solgne 从想做到能做
 * @Desc
 */
@RestController
@RequestMapping("/user")
@Api(tags ="用户api")
@CrossOrigin
public class UserController {
    @Resource
    private UserService userService;

//    @GetMapping ("/getone")
//    @NoLoginCheck
//    @ApiOperation(value = "账号密码登录")
//    public R get(Integer id){
//        System.out.println("测试");
//        return R.ok(id);
//    }

    @PostMapping("/addUser")
    @NoLoginCheck
    @ApiOperation(value = "根据手机号或邮箱和密码进行用户注册")
    public R addUser(@RequestBody User user) {
        userService.addUser(user);
        return R.ok("注册成功");
    }

    @PostMapping("/upload/avatar")
    @NoLoginCheck
    @ApiOperation(value = "头像上传")
    public R uploadavatar(MultipartFile file) {
        String path = userService.uploadavatar(file);
        return R.ok(path);
    }


    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @PostMapping("/updateUser")
    @ApiOperation(value = "修改用户信息")
    public R updateUser(@RequestBody UserParam user){
        userService.updateUser(user);
        return R.ok("修改成功");
    }

    @GetMapping("/findUserById")
    @ApiOperation(value = "根据id查询用户信息")
    public R findUserById(){
        UserParam user = userService.findUserById();
        return R.ok(user);
    }


    @PostMapping("/updateBackground")
    @ApiOperation(value = "背景图修改")
    public R updateBackground(MultipartFile file){
        userService.updateBackground(file);
        return R.ok("背景修改成功");
    }
}
